import { NodePath } from '@babel/traverse'
import { FunctionDeclaration } from '@babel/types'
import { methodsInfoTypes } from '../types/class'
import { ASTResult } from '../types/ops'
import { methodDescription } from './class'
import { resolveType } from './type'
/**
 * @description 获取函数参数
 */
export function getFuncParamsList(path: NodePath<FunctionDeclaration>): { name: string; type: string }[] {
  return (
    path.get('params').map(paramsPath => {
      return {
        name: paramsPath.toString(),
        // @ts-ignore
        type: resolveType(paramsPath.getTypeAnnotation()),
      }
    }) || []
  )
}

export function getDesc(contentItem: ASTResult): string {
  if (!contentItem.doc) return ''
  return methodDescription(contentItem as methodsInfoTypes)
}
